package com.kantboot.file.controller;

import com.kantboot.file.config.KantbootFileSettingConfig;
import com.kantboot.file.entity.CesKantbootFile;
import com.kantboot.file.service.CesKantbootFileService;
import com.kantboot.util.common.RestResult;
import lombok.SneakyThrows;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

@RestController()
@RequestMapping("/kantboot/file")
public class CesKantbootController {

    @Resource
    CesKantbootFileService cesKantbootFileService;

    /**
     * 查看文件
     * @param typeStr
     * @param id
     * @param response
     */
    @SneakyThrows
    @RequestMapping("/view/{type_str}/{id}")
    public void view(@PathVariable("type_str") String typeStr,@PathVariable("id") Integer id, HttpServletResponse response) {
        cesKantbootFileService.showFileById(id,typeStr,response);
    }

    @SneakyThrows
    @RequestMapping(value = "/upload/{type_str}", method = RequestMethod.POST, consumes = "multipart/form-data")
    public RestResult<CesKantbootFile> upload(
            @PathVariable("type_str") String typeStr,
            @RequestParam("file") MultipartFile file){
        return RestResult.success(cesKantbootFileService.upload(file,typeStr), "上传成功");
    }

    /**
     * 查看设置信息
     * @return
     */
    @RequestMapping("/setting/show")
    public RestResult<KantbootFileSettingConfig> settingShow() {
        return RestResult.success(KantbootFileSettingConfig.newInstance(),"查看成功");
    }

    @RequestMapping("/setting/edit")
    public RestResult<KantbootFileSettingConfig> settingEdit() {
        return RestResult.success(KantbootFileSettingConfig.newInstance(),"查看成功");
    }



}
